package com.fanbai.score.common.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.text.TextUtils;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.fanbai.score.R;
import com.fanbai.score.common.Utils.ToastUtils;


public class MyLayoutDialog extends Dialog {

    public MyLayoutDialog(Activity context) {
        this(context, 0);
    }

    public MyLayoutDialog(Activity context, int themeResId) {
        super(context, themeResId);
    }

    private static void setW_H(Activity activity, Dialog dialog){
        Window window = dialog.getWindow() ;
        WindowManager m = activity.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
//        p.height = (int) (d.getHeight() * 0.5); // 高度设置为屏幕的0.5
        p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.8
        window.setAttributes(p);
    }

    static private MyLayoutDialog dialog;
    public static MyLayoutDialog instanceRenterAddUser(final Activity activity, final OnMyAlertDialogClick onMyAlertDialogClick){
        LinearLayout v = (LinearLayout) View.inflate(activity, R.layout.business_dialog_addshop, null);
        final EditText shopNameEdit = (EditText) v.findViewById(R.id.businessItemFragmentShop_shopNewName);
        final EditText shopAddEdit = (EditText) v.findViewById(R.id.businessItemFragmentShop_shopNewAddress);
        final EditText nameEdit = (EditText) v.findViewById(R.id.businessItemFragmentShop_userNewName);
        final EditText mobileEdit = (EditText) v.findViewById(R.id.businessItemFragmentShop_userNewMobile);
        dialog = new MyLayoutDialog(activity, R.style.loading_dialog);
        v.findViewById(R.id.businessItemFragmentShop_submitBut).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String shopName = shopNameEdit.getText().toString();
                String shopAddress = shopAddEdit.getText().toString();
                String userName = nameEdit.getText().toString();
                String userMobile = mobileEdit.getText().toString();
                if(TextUtils.isEmpty(shopName)){
                    ToastUtils.WarnImageToast(activity, "店铺名称不可为空");
                    return ;
                }
                if(TextUtils.isEmpty(shopAddress)){
                    ToastUtils.WarnImageToast(activity, "店铺地址不可为空");
                    return ;
                }
                if(TextUtils.isEmpty(userName)){
                    ToastUtils.WarnImageToast(activity, "联系人姓名不可为空");
                    return ;
                }
                if(TextUtils.isEmpty(userMobile)){
                    ToastUtils.WarnImageToast(activity, "联系人电话不可为空");
                    return ;
                }
                dialog.cancel();
                onMyAlertDialogClick.onMyAlertDialogClick(true, shopName, shopAddress,  userName, userMobile);
            }
        });
        dialog.setContentView(v,
                new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT)
        );
        setW_H(activity, dialog);
        return dialog;
    }

    @Override
    public void show() {

        super.show();
    }

    @Override
    public void hide() {
        super.hide();
    }


}
